Programmation PHP/Migration de Symfony 5 à 6
La liste des dépréciations cassantes en Symfony 6 est disponible dans le Profiler d'un projet Symfony 5.4, à la section logs.
YAML[modifier | modifier le wikicode]
- Dans
security.firewalls.main
, remplaceranonymous: true
parlazy: true
. Erreur sinon : Invalid firewall "main": user provider "users_in_memory" not found. - Dans
framework.session
, remplacerstorage_id: session.storage.mock_file
parstorage_factory_id: session.storage.factory.mock_file
. Erreur sinon : Unrecognized option "storage_id" under "framework.session".
PHP[modifier | modifier le wikicode]
- Remplacer les injections de
SessionInterface
parRequestStack
, et appeler sa méthodegetSession()
. Erreur sinon : "Cannot autowire service... SessionInterface".
Rector[modifier | modifier le wikicode]
Facultativement, on peut utiliser Rector pour convertir automatiquement les annotations en attributs[1].
Installation :
composer require rector/rector --dev vendor/bin/rector init
Ensuite, il suffit de mettre les règles voulues dans rector.php :
$rectorConfig->sets([ LevelSetList::UP_TO_PHP_81, DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, SensiolabsSetList::FRAMEWORK_EXTRA_61, ]);
Si cela ne marche pas (depuis la v1), créer rector.php soit-même :
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use Rector\Doctrine\Set\DoctrineSetList; use Rector\Set\ValueObject\LevelSetList; use Rector\Symfony\Set\SymfonySetList; return RectorConfig::configure() ->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml') ->withSets([ LevelSetList::UP_TO_PHP_82, SymfonySetList::SYMFONY_CODE_QUALITY, SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, ]);
Puis lancer la modification des fichiers :
vendor/bin/rector process src
Si les entités modifiées ne marchent plus (is not a valid entity or mapped super class), mettre à jour "doctrine/orm": "^2.9"
[2] et dans doctrine.yaml, "type: annotation" par "type: attribute".
Twig[modifier | modifier le wikicode]
- Remplacer
controller(App\\Controller\\HomeController:headerAction)
par(App\\Controller\\HomeController::headerAction)
. Sinon, prendre le nom du contrôleur avec sa méthode visible dansbin/console debug:router --show-controllers
en échappant ses antislashs. Erreur sinon : The controller for URI "/_fragment" is not callable.